import NProgress from "nprogress";
import "nprogress/nprogress.css";

//关闭顶部右侧的旋转加载
NProgress.configure({showSpinner: false});

import {createRouter, createWebHistory, createWebHashHistory} from 'vue-router'
import viewsRoutes from '@/router/routes.js'

// console.log(viewsRoutes)


const routes = [
    {
        path: '/',
        name: "main",
        component: () => import('@/layout/index.vue'),
        redirect: "/index",
        children: viewsRoutes
    },
    {
        path: '/login',
        name: "login",
        component: () => import('@/views/login/index.vue'),
        meta:{
            title:'登陆'
        }
    }
]


const router = createRouter({
    history: createWebHistory(),
    // history:createWebHashHistory(),
    routes,
})


router.beforeEach(async (to, from, next) => {

    NProgress.start();

    // if (to.matched.length == 0) {router.push(to.path);}

    next();

})

router.afterEach((to, from, failure) => {
    if (to.meta.title) {
        document.title = to.meta.title;
    }
    NProgress.done();
})

export default router;

